<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Trang giỏ hàng </title>

<link href="../style/cs1.css" rel="stylesheet" type="text/css" />
 <script>
  function check()
  {
	  var s=document.form1;
  	if(s.tongtien.value==0)
	{
		alert('ban chua có mat hang');
	}
    else
    {
    	location.href='index.php?act=dh';
    }
  }
  </script>
</head>

<body>
<?php
include("check_userlogin.php");
$Malaptop = $_GET["Malaptop"];
include("config/config.php");
$kt = 0;
for($i = 1; $i <= $_SESSION["tongsp"]; $i++)
{
	if($_GET["Malaptop"]==$_SESSION["Malaptop".$i])
	{
		$kt = 1;
		$_SESSION["Soluong".$i]++;
		break;
		
	}
	
}

if($kt==0)
{
	$lenh = "select * from laptop where Malaptop='$Malaptop'";
	$kq = mysql_query($lenh);
	$n = mysql_num_rows($kq);
	if($n > 0)
	{
		$_SESSION["tongsp"]++;
		$row = mysql_fetch_array($kq);
		$j = $_SESSION["tongsp"];
		session_register("Malaptop".$j);
		$_SESSION["Malaptop".$j] = $row["Malaptop"];
		session_register("Tenlaptop".$j);
		$_SESSION["Tenlaptop".$j] = $row["Tenlaptop"];
		session_register("Dongia".$j);
		$_SESSION["Dongia".$j] = $row["Dongia"];
		session_register("Soluong".$j);
		$_SESSION["Soluong".$j] = 1;
	}
	
}


?>
<form id="form1" name="form1" method="post" action="giohang/capnhatgiohang.php">
  <table width="900" border="1" align="center" cellpadding="0" cellspacing="0" class="manh">
    <tr>
      <td height="30" colspan="6" align="center"><p><strong>DANH SÁCH ĐẶT HÀNG</strong></p>
      <p><strong>
        <input name="tieptuc" type="button" class="nutgiohang" id="tieptuc" onclick="location.href='index.php'" value="Tiếp tục mua hàng" />
      </strong></p>
      <p>&nbsp;</p></td>
    </tr>
    <tr>
      <td height="50" align="center"><strong>STT</strong></td>
      <td height="50" align="center"><strong>Tên laptop</strong></td>
      <td height="50" align="center"><strong>Đơn giá</strong></td>
      <td height="50" align="center"><strong>Số lượng </strong></td>
      <td height="50" align="center"><strong>Thành tiền </strong></td>
      <td height="50" align="center"><strong>Xóa</strong></td>
    </tr>
    <?php
	for($i = 1; $i <= $_SESSION["tongsp"];$i++)
	{
		?>
    <tr>
      <td height="50" align="center"><?php  echo $i;  ?></td>
      <td height="50" align="center"><?php echo $_SESSION["Tenlaptop".$i];    ?></td>
      <td height="50" align="center"><?php echo $_SESSION["Dongia".$i];    ?></td>
      <td height="50" align="center"><label for="soluong"></label>
      <input name="C<?php  echo $i;  ?>" type="text" class="otongtien" id="soluong" value="<?php echo $_SESSION["Soluong".$i];    ?>" size="10" readonly="readonly" /></td>
      <td height="50" align="center"><?php echo $_SESSION["Soluong".$i]*$_SESSION["Dongia".$i];    ?></td>
      <td height="50" align="center"><input type="checkbox" name="X<?php   echo $i;  ?>" id="xoa" />
      <label for="xoa"></label></td>
    </tr>
    <?php
	}
	?>
  </table>
  <?php
  function tongtien()
  {
	  $s = 0;
	  for($i = 1; $i <=$_SESSION["tongsp"];$i++)
	  {
		  $s = $s + $_SESSION["Soluong".$i]*$_SESSION["Dongia".$i];
		  
	  }
	  return $s;
  }
  
  ?>
  <p align="center" style="font-size:30px;">Tổng tiền:
    <label for="tongtien"></label>
    <input name="tongtien" type="text" class="otongtien" id="tongtien" value=<?php echo number_format(tongtien(),0,',','.'); ?> readonly="readonly" />
VNĐ </p>
  <p align="center">
    <input name="capnhat" type="submit" class="nutgiohang" id="capnhat" value="Cập nhật" />&nbsp;
    <input name="dathang" type="button" class="nutgiohang" id="dathang" onclick="return check();" value="Đặt hàng" />&nbsp;
    <input name="xoa" type="submit" class="nutgiohang" id="xoa" value="Xóa" />
  </p>
  <p align="center">&nbsp;</p>
  <p>&nbsp;</p>
</form>
</body>
</html>